package com.example.hhh.controller;

import com.example.hhh.model.WorkOrder;
import com.example.hhh.service.WorkOrderService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/work-orders")
public class WorkOrderController {

    private final WorkOrderService workOrderService;

    public WorkOrderController(WorkOrderService workOrderService) {
        this.workOrderService = workOrderService;
    }

    @PostMapping
    public ResponseEntity<WorkOrder> createWorkOrder(@RequestBody WorkOrder workOrder) {
        return ResponseEntity.ok(workOrderService.createWorkOrder(workOrder));
    }

    @GetMapping("/by-customer/{customerId}")
    public ResponseEntity<List<WorkOrder>> getOrdersByCustomer(
            @PathVariable Integer customerId) {
        return ResponseEntity.ok(
                workOrderService.getOrdersByCustomer(customerId));
    }

    @GetMapping("/by-staff/{staffId}")
    public ResponseEntity<List<WorkOrder>> getOrdersByStaff(
            @PathVariable Integer staffId) {
        return ResponseEntity.ok(
                workOrderService.getOrdersByStaff(staffId));
    }
}